package com.manager.core.module.manager.controller;

import com.manager.commons.annotation.Module;
import com.manager.commons.annotation.Operation;
import com.manager.commons.base.DataGrid;
import com.manager.core.module.log.aop.TMLog;
import com.manager.core.web.json.AjaxJson;
import com.manager.core.module.manager.entity.GenAdvertising;
import com.manager.core.module.manager.service.GenAdvertisingService;
import com.manager.gen.web.controller.AdminController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

/**
 * GenAdvertisingController
 * 轮播图管理
 *
 * @author manager
 * @version 1.0
 */
@Controller()
@Module(parent = "centent-manager", title = "轮播图管理", code = "/gen/article/advertising",sort = 2)
public class GenAdvertisingController extends AdminController<GenAdvertising> {
    private final String baseUrl = "/gen/article/advertising";
    @Autowired
    private GenAdvertisingService _service;

    /**
     * 列表
     *
     * @return
     */
    @TMLog(type = "mvp", description = "轮播图管理列表页面")
    @RequestMapping(baseUrl + "/index")
    public ModelAndView index() {
        return getModelAndView(baseUrl + "/advertising-index");
    }

    /**
     * 新增
     *
     * @return
     */
    @TMLog(type = "mvp", description = "新增轮播图管理页面")
    @GetMapping(baseUrl + "/add")
    @Operation(title = "新增")
    public ModelAndView add() {
        return getModelAndView(baseUrl + "/advertising-edit", getModel());
    }

    /**
     * 新增
     *
     * @return
     */
    @TMLog(type = "mvp", description = "编辑轮播图管理")
    @RequestMapping(baseUrl + "/edit")
    @Operation(title = "编辑")
    public ModelAndView edit() {
        return getModelAndView(baseUrl + "/advertising-edit", _service.findMap(getParams()));
    }


    /**
     * 删除数据
     *
     * @return
     */
    @RequestMapping(value = baseUrl + "/delete", method = RequestMethod.POST)
    @Operation(title = "删除")
    public @ResponseBody AjaxJson delete() {
        return _service.delete(getParams());
    }


    /**
     * 分页
     *
     * @return
     */
    @TMLog(type = "rmp", description = "轮播图管理列表分页[post]。")
    @RequestMapping(value = baseUrl + "/list")
    @Operation(title = "列表")
    public @ResponseBody DataGrid page() {
        return _service.queryPage(getParams());
    }

    /**
     * 保存
     *
     * @returna
     */
    @TMLog(type = "rmp", description = "保存轮播图管理数据[post]。")
    @PostMapping(value = baseUrl + "/save")
    public @ResponseBody AjaxJson save() {
        try {
            return _service.save(getParams());
        } catch (Exception e) {
            e.printStackTrace();
            logger.error(e.getMessage(), e);
        }
        return new AjaxJson("异常错误，请稍后再试");
    }

    /**
     * 改变数据状态
     *
     * @return
     */
    @TMLog(type = "rmp", description = "修改轮播图管理数据状态(禁用/启用)[post]。")
    @PostMapping(value = baseUrl + "/status")
    @Operation(title = "状态修改")
    public @ResponseBody AjaxJson status() {
        return _service.status(getParams());
    }


    @Override
    public GenAdvertising getModel() {
        return new GenAdvertising();
    }

}
